package com.doradance.main.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.doradance.R;
import com.doradance.model.remote.bean.HotListBean;
import com.doradance.view.recyclerview.SimpleCellListAdapter;
import com.doradance.view.recyclerview.ViewHolderModel;
import com.yong.android.framework.view.CircleImageView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/12/21.
 */

public class CommunityAdapter extends SimpleCellListAdapter<CommunityAdapter.CommunityHolder, HotListBean.ItemBean> {
    public static final int TYPE_HEADER = 0;
    public static final int TYPE_NORMAL = 1;
    private View mHeaderView;
    private Context mContext;
    public CommunityAdapter(Context context) {
        super(context);
        mContext = context;
        openLoadMore();

        setLayoutManager(new LinearLayoutManager(context));
//        setItemDecoration(new DivderItemDecoration(context, DivderItemDecoration.VERTICAL_LIST));
    }


    public void setHeaderView(View headerView) {
        mHeaderView = headerView;
    }


    @Override
    public CommunityHolder onCreateViewHolder(LayoutInflater inflater, ViewGroup parent, int viewType) {
        if(mHeaderView!=null){
            return new CommunityHolder(inflater,parent);
        }
        return new CommunityHolder(inflater,parent);
    }

    @Override
    public void onBindViewHolder(CommunityHolder holder, int position) {
        holder.bindModel(getItem(position));
    }

    //itemHolder
    static class CommunityHolder extends ViewHolderModel<HotListBean.ItemBean> {
        @Bind(R.id.iv_avatar)
        CircleImageView mIvAvatar;
        @Bind(R.id.tv_name)
        TextView mTvName;
        @Bind(R.id.iv_gender)
        ImageView mIvGender;
        @Bind(R.id.tv_age)
        TextView mTvAge;
        @Bind(R.id.tv_home_top1)
        TextView mTvHomeTop1;
        @Bind(R.id.tv_home_top2)
        TextView mTvHomeTop2;
        @Bind(R.id.tv_home_top3)
        TextView mTvHomeTop3;
        @Bind(R.id.llLayout)
        LinearLayout mLlLayout;
        @Bind(R.id.tv_charm)
        TextView mTvCharm;
        @Bind(R.id.iv_cover)
        ImageView mIvCover;
        @Bind(R.id.tv_title)
        TextView mTvTitle;
        @Bind(R.id.tv_price)
        TextView mTvPrice;
        @Bind(R.id.fl_container)
        FrameLayout mFlContainer;

        Context mContext;

        public CommunityHolder(LayoutInflater inflater,ViewGroup parent) {
            super(inflater.inflate(R.layout.list_item_home_anchor, parent, false));
            mContext = parent.getContext();
        }



        @Override
        public void bindModel(HotListBean.ItemBean item) {
            mTvAge.setText(item.getAge());
            mTvName.setText(item.getNickname());
            mTvCharm.setText("魅力值："+item.getCharm());
            Glide.with(mContext).load(item.getAvatar()).into(mIvAvatar);
            Glide.with(mContext).load(item.getCover()).into(mIvCover);

        }

        @Override
        protected void bindView() {
            ButterKnife.bind(this,itemView);super.bindView();
        }
    }

}
